//
//  QSEclipseOpenActionProvider.m
//  MyPlugin
//
//  Created by Brad Reynolds on 2/4/07.
//  Copyright 2007 __MyCompanyName__. All rights reserved.
//

#import "QSEclipseOpenActionProvider.h"
#import "QSEclipsePlugin.h"

@implementation QSEclipseOpenActionProvider
+ (void)openWorkspace:(id) qsObject {
	//Since this method is invoked in a separate Thread a new autorelease pool must be created.
	NSAutoreleasePool *threadPool = [[NSAutoreleasePool alloc] init];
	NSUserDefaults *userDefaults = [[QSEclipsePlugin sharedInstance] userDefaults];
	
	//If this is a recent workspace the parent eclipse path will be set.
	NSString *path = [qsObject objectForType:QSEclipseParentEclipse];
	if (path == nil) {
		path = [userDefaults stringForKey:QSEclipsePath];		
	}
	
	NSString *command = [NSString stringWithFormat:[userDefaults stringForKey:QSEclipseRunCommand], path, [qsObject objectForType:QSEclipseWorkspaceType]];
	
	system([command UTF8String]);
	[threadPool release];
}

- (QSObject *) performMyAction:(QSObject *)dObject
{
	[NSThread detachNewThreadSelector:@selector(openWorkspace:) toTarget:[QSEclipseOpenActionProvider class] withObject:dObject];
    return nil;
}
@end
